//
//  JSSettingMoodVC.m
//  NiubilityProject
//
//  Created by Apple on 2017/12/2.
//  Copyright © 2017年 Apple. All rights reserved.
//

#import "JSSettingMoodVC.h"

@interface JSSettingMoodVC ()<QMUITextViewDelegate>
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpace;
@property (weak, nonatomic) IBOutlet UILabel *topTitleL;
@property (weak, nonatomic) IBOutlet UIButton *cancleBtn;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;

@property (weak, nonatomic) IBOutlet UILabel *numberL;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftSpace;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightSpace;

@end

@implementation JSSettingMoodVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    JS_WeakSelf(self)
    
   RACSignal *enableSingal = [[self rac_signalForSelector:@selector(textViewDidChange:) fromProtocol:@protocol(QMUITextViewDelegate)]map:^id(id value) {
       weakself.confirmBtn.enabled = YES;
       QMUITextView *tv = value[0];
       weakself.numberL.text = NSStringFormat(@"%zd/256",tv.text.length);
        return @(tv.text.length);
    }];
    self.confirmBtn.rac_command = [[RACCommand alloc] initWithEnabled:enableSingal signalBlock:^RACSignal *(id input) {
        JSLog(@"input %@", input);
        return [RACSignal empty];
    }];
    
    [self didInitializ];
}

- (void)didInitializ{
  
    self.leftSpace.constant = self.rightSpace.constant = kRealValue(10);
    self.topTitleL.text = JSLocalizedString(@"MySignature");
    self.numberL.text = NSStringFormat(@"%zd/256",self.textView.text.length);
    self.confirmBtn.enabled = self.textView.text.length;
    [self.cancleBtn setTitle:JSLocalizedString(kLocalizableCancel) forState:UIControlStateNormal];
    [self.confirmBtn setTitle:JSLocalizedString(kLocalizableOk) forState:UIControlStateNormal];
    self.textView.placeholder = JSLocalizedString(@"placeholdNumber");
    self.textView.text = self.mood;
}
- (IBAction)cancelClick:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)confirmClick:(id)sender {
    if (self.EnterMood) {
        self.EnterMood(self.textView.text);
    }
    [self cancelClick:nil];
}



@end
